<?php

class Model_DbTable_Pr_Transrecord extends Zend_Db_Table_Abstract {

	protected $_name = 'repair_transfer_record';
	
	public function getTransrecord( $idRecord){
		
		$row = $this->fetchRow("`id_record` = ". $idRecord);
		if(!$row) return false;
		return $row->toArray();		
		
		}
		
	public function getLastrecord( $idJob){
		$row = $this->fetchRow("`id_job` = ". $idJob);
		if(!$row) return false;
		return $row->toArray();
		
	}
	
	public function getLastTrack( $idJob){
		$row = $this->fetchRow("`id_job` = ". $idJob. " AND `id_reason` = 0","id_record DESC ");
		if(!$row) return false;
		return $row->toArray();
	
	}
	
		
	public function addTransrecord( $idJob , $shopCode , $idStaff , $dateRecord , $timeRecord , $idStatus , $comment , $idReason){
		
		$data = array(
			
         "id_job" =>  $idJob ,
         "shop_code" =>  $shopCode ,
         "id_staff" =>  $idStaff ,
         "date_record" =>  $dateRecord ,
         "time_record" =>  $timeRecord ,
         "id_status" =>  $idStatus ,
         "comment" =>  $comment ,
         "id_reason" =>  $idReason 
	
			);
		$this->insert($data);
		
		}
		
	public function updateTransrecord(  $idRecord ,  $idJob , $shopCode , $idStaff , $dateRecord , $timeRecord , $idStatus , $comment , $idReason){
		$data = array(
			
         "id_job" =>  $idJob ,
         "shop_code" =>  $shopCode ,
         "id_staff" =>  $idStaff ,
         "date_record" =>  $dateRecord ,
         "time_record" =>  $timeRecord ,
         "id_status" =>  $idStatus ,
         "comment" =>  $comment ,
         "id_reason" =>  $idReason 
	
			);
			
		$this->update($data,"`id_record` = ". $idRecord);
		}
		
	public function deleteTransrecord( $idRecord){
		
		$this->delete("`id_record` = ". $idRecord);
		
		}	
	
	public function listAll(){
		
		$rows =$this->fetchAll("1","id_record DESC ");
		if(!$rows) return false;
		return $rows->toArray();			
		
		}	
	public function getJobHistory($idJob){
		$rows =$this->fetchAll("`id_job` = {$idJob}","time_record")->toArray();
		if(!(boolean)$rows) return false;
		return $rows;
		
	}	
	public function getLastJobLocation($idJob){
		$row = $this->fetchRow("`id_job` = {$idJob}","time_record DESC");
		return $row->toArray();
	}	
}


?>